package com.pattern.structural.decorator;

import java.io.InputStream;

/**
 * @Description
 *   Demo for decorator pattern
 * @Author Ping
 * @Date 2022/4/11 14:16
 **/
public class DecoratorDemo {

    InputStream in ;

    public static void main(String args[]) {

        Car car = new Car() ;
        Car robotCar = new RobortTransform(car) ;
        Car airCar = new AirplaneTransform(robotCar) ;

        car.action();
        robotCar.action();
        airCar.action() ;

    }

}

/**
 * Component role
 */
class Car {

    public void action() {
        System.out.println("car is moving.") ;
    }
}

/**
 * Decorator :
 *  1. it was a car
 *  2. it was related to a car
 */
abstract class Transform extends Car {
    protected Car car ;

    public Transform(Car car) {
        this.car = car;
    }

    /**
     * common methods for each decorators.
     * Additional functionals.
     */
    public abstract void transform() ;
    @Override
    public void action() {
        this.car.action();
        this.transform();

    }
}

/**
 * Concrete decorator.
 */
class RobortTransform extends Transform {
    public RobortTransform(Car car) {
        super(car);
    }

    @Override
    public void transform() {
        System.out.println("the car transform to a ROBORT.") ;
    }
}

class AirplaneTransform extends Transform {
    public AirplaneTransform(Car car) {
        super(car);
    }

    @Override
    public void transform() {
        System.out.println("the car transform to an Airplane.") ;
    }
}









